<?php
namespace app\api\model;
use think\Model;
use app\api\mdoel\Details;
class Issue extends Model
{
    public function index($ispre){
        error_reporting(0);
        $information = model('issue')
            ->alias('a')
            ->join('indent','a.id = indent.issueid','left')
            ->join('classify','a.classifyid=classify.id','left')
            ->join('brand','a.brandid=brand.id','left')
            ->where('ispre',$ispre)
            ->group('a.id')
            ->field('a.*,sum(indent.number) as ct,classify.name classifyname,brand.name brandname')
            ->select();
        if(count($information)==0)
        {
            return 0;
        }
        else
        {
            return $information;
        }
    }

    public function details($id)
    {
        error_reporting(0);
        $data = model('issue')
            ->alias('a')
            ->join('details b','b.issueid=a.id','left')
            ->join('classify c','a.classifyid=c.id','left')
            ->join('indent d','d.issueid = a.id','left')
            ->where('a.id',$id)
            ->field('a.id,a.name goodsname,c.name classsifyname,a.photo,a.inventory kucun,sum(d.number) as xiaoliang,a.area,bazaar,stand,active,cost,b.url')
            ->select();
        //商品名字、分类、商品主图、库存、销量、产地、价格
        if(count($data) == 0)
        {
            return 0;
        }
        else
        {
            return $data;
        }
    }
}